/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package pe.edu.pucp.views;

import java.awt.event.KeyEvent;
import java.util.ArrayList;
import javax.swing.ButtonGroup;
import javax.swing.JOptionPane;
import javax.swing.table.AbstractTableModel;
import pe.edu.pucp.Servicio.Servicio_Cliente;
import pe.edu.pucp.bean.Cliente;
import pe.edu.pucp.bean.Internacional;
import pe.edu.pucp.bean.Nacional;

/**
 *
 * @author LiziTa
 */
public class PanelClienteEditar extends javax.swing.JPanel {
    /**
     * Creates new form PanelClienteEditar
     */

Servicio_Cliente service = Servicio_Cliente.get_instance();
	public int choice;
	
	PanelClienteEditar.ClienteTableModel miclienteTM = new PanelClienteEditar.ClienteTableModel();

	public void Actualizar(){
            miclienteTM.clientes=service.queryAllClientes();
            miclienteTM.fireTableChanged(null);
        }
       
    private void groupButton( ) {

    ButtonGroup bg1 = new ButtonGroup( );

    bg1.add(RBNacional);
    bg1.add(RBInter);   
    }
	
	class ClienteTableModel extends AbstractTableModel{
        
               
        String Titulos[]={"ID","RUC","R.SOCIAL","DIRECCION","REPRESENTANTE","L.CREDITO","DEPARTAMENTO","CIUDAD","DIVISA","PAIS"};
        ArrayList<Cliente>clientes = service.queryAllClientes(); 
               
        @Override
        public int getRowCount() {
            return clientes.size();
        }

        @Override
        public int getColumnCount() {
            return 10;
        }

        @Override
        public Object getValueAt(int fil, int col) {
            String res=null;
            Cliente c = clientes.get(fil);
            String tipo=c.getTipo();
            
            switch (col){
                case 0 : res=""+c.getId();break;
                case 1 : res= c.getRUC();break;
                case 2 : res= c.getRazonSocial();break;
                case 3 : res= c.getDireccion();break;
                case 4 : res= c.getRepresentante();break;
                case 5 : res=""+c.getLineaCred(); break;
                case 6 : if (c instanceof Nacional) {
                         res=((Nacional)c).getDepartamento();
                         break;
                        }
                else {
                    res="       -";
                    break;
                }
                case 7 : if (c instanceof Nacional) {
                         res=((Nacional)c).getCiudad();
                         break;
                        }
                else {
                    res="    -";
                    break;
                }
                case 8 : if (c instanceof Internacional) {
                         res=""+((Internacional)c).getDivisa();
                         break;
                        }
                else {
                    res="     -";
                    break;
                }
                case 9 : if (c instanceof Internacional) {
                         res=((Internacional)c).getPais();
                         break;
                        }
                else {
                    res="     -";
                    break;
                }
            }
            return res;
        }
        
        @Override
        public String getColumnName(int col){
            return Titulos[col];
        }
        
        }
    public PanelClienteEditar() {
        initComponents();
        TablaCliente.setModel(miclienteTM);
        groupButton();
      
    }
      
    

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        jPanel2 = new javax.swing.JPanel();
        txtRep = new javax.swing.JTextField();
        jLabel1 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        jLabel7 = new javax.swing.JLabel();
        txtId = new javax.swing.JTextField();
        txtRuc = new javax.swing.JTextField();
        txtRazon = new javax.swing.JTextField();
        txtDir = new javax.swing.JTextField();
        jLabel5 = new javax.swing.JLabel();
        txtLinea = new javax.swing.JFormattedTextField();
        jPanel3 = new javax.swing.JPanel();
        jLabel11 = new javax.swing.JLabel();
        RBInter = new javax.swing.JRadioButton();
        jLabel10 = new javax.swing.JLabel();
        jLabel8 = new javax.swing.JLabel();
        RBNacional = new javax.swing.JRadioButton();
        jLabel9 = new javax.swing.JLabel();
        cmbPais = new javax.swing.JComboBox();
        cmbDep = new javax.swing.JComboBox();
        cmbCiu = new javax.swing.JComboBox();
        txtDiv = new javax.swing.JFormattedTextField();
        jLabel12 = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        TablaCliente = new javax.swing.JTable();
        javax.swing.JButton Editar = new javax.swing.JButton();
        jButton2 = new javax.swing.JButton();

        jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder(javax.swing.BorderFactory.createEtchedBorder(), "Datos Cliente"));

        txtRep.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyReleased(java.awt.event.KeyEvent evt) {
                txtRepKeyReleased(evt);
            }
            public void keyTyped(java.awt.event.KeyEvent evt) {
                txtRepKeyTyped(evt);
            }
        });

        jLabel1.setText("Código:");

        jLabel3.setText("Razón Social:");

        jLabel2.setText("Ruc:");

        jLabel4.setText("Dirección:");

        jLabel6.setText("Representante:");

        jLabel7.setText("Linea de Crédito:");

        txtId.setEnabled(false);
        txtId.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txtIdActionPerformed(evt);
            }
        });
        txtId.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyReleased(java.awt.event.KeyEvent evt) {
                txtIdKeyReleased(evt);
            }
        });

        txtRuc.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyReleased(java.awt.event.KeyEvent evt) {
                txtRucKeyReleased(evt);
            }
            public void keyTyped(java.awt.event.KeyEvent evt) {
                txtRucKeyTyped(evt);
            }
        });

        txtRazon.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txtRazonActionPerformed(evt);
            }
        });
        txtRazon.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                txtRazonKeyTyped(evt);
            }
        });

        txtDir.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                txtDirKeyTyped(evt);
            }
        });

        jLabel5.setIcon(new javax.swing.ImageIcon(getClass().getResource("/pe/edu/pucp/views/logo.gif"))); // NOI18N

        txtLinea.setText(" ");
        txtLinea.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                txtLineaKeyTyped(evt);
            }
        });

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel1)
                    .addComponent(jLabel3)
                    .addComponent(jLabel4)
                    .addComponent(jLabel2))
                .addGap(46, 46, 46)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(txtDir)
                            .addComponent(txtRazon)
                            .addComponent(txtId, javax.swing.GroupLayout.PREFERRED_SIZE, 133, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 25, Short.MAX_VALUE)
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel6)
                            .addComponent(jLabel7))
                        .addGap(28, 28, 28)
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(txtRep, javax.swing.GroupLayout.DEFAULT_SIZE, 111, Short.MAX_VALUE)
                            .addComponent(txtLinea)))
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addComponent(txtRuc, javax.swing.GroupLayout.PREFERRED_SIZE, 133, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(jLabel5)))
                .addContainerGap())
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addContainerGap()
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(txtId, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel1))
                        .addGap(18, 18, 18)
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel2)
                            .addComponent(txtRuc, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(18, 18, 18)
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel3)
                            .addComponent(txtRazon, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel6)
                            .addComponent(txtRep, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(26, 26, 26)
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel4)
                            .addComponent(txtDir, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
                        .addComponent(jLabel5, javax.swing.GroupLayout.PREFERRED_SIZE, 60, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel7)
                            .addComponent(txtLinea, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(3, 3, 3)))
                .addContainerGap(14, Short.MAX_VALUE))
        );

        jPanel3.setBorder(javax.swing.BorderFactory.createTitledBorder(javax.swing.BorderFactory.createEtchedBorder(), "Tipo Cliente", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, null, new java.awt.Color(0, 0, 0)));

        jLabel11.setText("Pais:");

        RBInter.setSelected(true);
        RBInter.setText("Internacional");
        RBInter.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                RBInterActionPerformed(evt);
            }
        });

        jLabel10.setText("Divisa:");

        jLabel8.setText("Departamento:");

        RBNacional.setText("Nacional");
        RBNacional.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                RBNacionalActionPerformed(evt);
            }
        });

        jLabel9.setText("Ciudad:");

        cmbPais.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Seleccionar", "Afganistan", "Africa del Sur", "Albania", "Alemania", "Andorra", "Angola", "Antigua y Barbuda", "Antillas Holandesas", "Arabia Saudita", "Argelia", "Argentina", "Armenia", "Aruba", "Australia", "Austria", "Azerbaijan", "Bahamas", "Bahrain", "Bangladesh", "Barbados", "Belarusia", "Belgica", "Belice", "Benin", "Bermudas", "Bolivia", "Bosnia", "Botswana", "Brasil", "Brunei Darussulam", "Bulgaria", "Burkina Faso", "Burundi", "Butan", "Camboya", "Camerun", "Canada", "Cape Verde", "Chad", "Chile", "China", "Chipre", "Colombia", "Comoros", "Congo", "Corea del Norte", "Corea del Sur", "Costa de Marfíl", "Costa Rica", "Croasia", "Cuba", "Dinamarca", "Djibouti", "Dominica", "Ecuador", "Egipto", "El Salvador", "Emiratos Arabes Unidos", "Eritrea", "Eslovenia", "España", "Estados Unidos", "Estonia", "Etiopia", "Fiji", "Filipinas", "Finlandia", "Francia", "Gabon", "Gambia", "Georgia", "Ghana", "Granada", "Grecia", "Groenlandia", "Guadalupe", "Guam", "Guatemala", "Guayana Francesa", "Guerney", "Guinea", "Guinea-Bissau", "Guinea Equatorial", "Guyana", ":\tHaiti", "Holanda", "Honduras", "Hong Kong", "Hungria", "India", "Indonesia", "Irak", "Iran", "Irlanda", "Islandia", "Islas Caiman", "Islas Faroe", "Islas Malvinas (Falkland Islands)", "Islas Marshall", "Islas Solomon", "Islas Virgenes (U.S.)", "Israel", "Italia", "Jamaica", "Japon", "Jersey", "Jordania", "Kazakhstan", "Kenia", "Kiribati", "Kuwait", "Kyrgyzstan", "Laos", "Latvia", "Lesotho", "Libano", "Liberia", "Libia", "Liechtenstein", "Lituania", "Luxemburgo", "Macao", "Macedionia", "Madagascar", "Malasia", "Malawi", "Maldivas", "Mali", "Malta", "Marruecos", "Martinica", "Mauricio", "Mauritania", "Mexico", "Micronesia", "Moldova", "Monaco", "Mongolia", "Mozambique", "Myanmar (Burma)", "Namibia", "Nepal", "Nicaragua", "Niger", "Nigeria", "Noruega", "Nueva Caledonia", "Nueva Zealandia", "Oman", "Pakistan", "Palestina", "Panama", "Papua Nueva Guinea", "Paraguay", "Peru", "Polinesia Francesa", "Polonia", "Portugal", "Puerto Rico", "Qatar", "Reino Unido", "Republica Centroafricana", "Republica Checa", "Republica Democratica del Congo", "Republica Dominicana", "Republica Eslovaca", "Reunion", "Ruanda", "Rumania", "Rusia", "Sahara", "Samoa", "San Cristobal-Nevis (St. Kitts)", "San Marino", "San Vincente y las Granadinas", "Santa Lucia", "Santa Sede (Vaticano)", "Sao Tome & Principe", "Senegal", "Seychelles", "Sierra Leona", "Singapur", "Siria", "Somalia", "Sri Lanka (Ceilan)", "Sudan", "Sudan del Sur", "Suecia", "Suiza", "Sur Africa", "Surinam", "Swaziland", "Tailandia", "Taiwan", "Tajikistan", "Tanzania", "Timor Oriental", "Togo", "Tonga", "Trinidad & Tobago", "Tunisia", "Turkmenistan", "Turquia", "Ucrania", "Uganda", "Union Europea", "Uruguay", "Uzbekistan", "Vanuatu", "Venezuela", "Vietnam", "Yemen", "Yugoslavia", "Zambia", "Zimbabwe" }));
        cmbPais.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cmbPaisActionPerformed(evt);
            }
        });

        cmbDep.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Seleccionar", "Amazonas", "Ancash", "Apurimac", "Arequipa", "Ayacucho", "Cajamarca", "Callao", "Cusco", "Huancavelica", "Huanuco", "Ica", "Junin", "La Libertad", "Lambayeque", "Lima", "Loreto", "Madre De Dios", "Moquegua", "Pasco", "Piura", "Puno", "San Martin", "Tacna", "Tumbes", "Ucayali" }));
        cmbDep.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cmbDepActionPerformed(evt);
            }
        });

        cmbCiu.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Lima", "Pisco", "Cajamarca", " " }));

        txtDiv.setText("  ");
        txtDiv.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                txtDivKeyTyped(evt);
            }
        });

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(RBInter)
                    .addGroup(jPanel3Layout.createSequentialGroup()
                        .addContainerGap()
                        .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel10)
                            .addComponent(jLabel11))
                        .addGap(32, 32, 32)
                        .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(cmbPais, 0, 112, Short.MAX_VALUE)
                            .addComponent(txtDiv))))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 86, Short.MAX_VALUE)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel3Layout.createSequentialGroup()
                        .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel8)
                            .addComponent(jLabel9))
                        .addGap(43, 43, 43)
                        .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(cmbDep, javax.swing.GroupLayout.PREFERRED_SIZE, 103, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(cmbCiu, javax.swing.GroupLayout.PREFERRED_SIZE, 103, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addContainerGap())
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel3Layout.createSequentialGroup()
                        .addComponent(RBNacional)
                        .addGap(172, 172, 172))))
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(RBInter)
                    .addComponent(RBNacional))
                .addGap(18, 18, 18)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jLabel10)
                        .addComponent(txtDiv, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jLabel8)
                        .addComponent(cmbDep, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addGap(22, 22, 22)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel11)
                    .addComponent(cmbPais, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jLabel9)
                        .addComponent(cmbCiu, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(26, Short.MAX_VALUE))
        );

        jLabel12.setText("Tabla de Clientes Tramarsa");

        TablaCliente.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "Title 1", "Title 2", "Title 3", "Title 4"
            }
        ));
        TablaCliente.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                TablaClienteMouseClicked(evt);
            }
        });
        jScrollPane1.setViewportView(TablaCliente);

        Editar.setText("Editar");
        Editar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                EditarActionPerformed(evt);
            }
        });

        jButton2.setText("Cancelar");
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane1))
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addContainerGap()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(155, 155, 155)
                        .addComponent(Editar)
                        .addGap(38, 38, 38)
                        .addComponent(jButton2))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jLabel12)))
                .addGap(0, 0, Short.MAX_VALUE))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(Editar)
                    .addComponent(jButton2))
                .addGap(22, 22, 22)
                .addComponent(jLabel12)
                .addGap(18, 18, 18)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 125, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(35, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(0, 20, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(0, 11, Short.MAX_VALUE))
        );
    }// </editor-fold>//GEN-END:initComponents

    private void txtRepKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtRepKeyReleased
        
    }//GEN-LAST:event_txtRepKeyReleased

    private void txtIdActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txtIdActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_txtIdActionPerformed

    private void txtIdKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtIdKeyReleased

     
    }//GEN-LAST:event_txtIdKeyReleased

    private void txtRucKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtRucKeyReleased



    }//GEN-LAST:event_txtRucKeyReleased

    private void txtRazonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txtRazonActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_txtRazonActionPerformed

    private void RBInterActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_RBInterActionPerformed
         txtDiv.setEditable(true);
        txtDiv.setText("");
        cmbPais.setEnabled(true); 
        cmbPais.setEditable(true);
        cmbDep.setEnabled(false);
        cmbDep.setEditable(false);
        cmbCiu.setEditable(false);
        cmbCiu.setEnabled(false);
        choice = 1;
    }//GEN-LAST:event_RBInterActionPerformed

    private void RBNacionalActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_RBNacionalActionPerformed
       cmbDep.setVisible(true);
        cmbCiu.setVisible(true);
        cmbDep.setEnabled(true);
        cmbCiu.setEnabled(true);
        txtDiv.setText("");
        txtDiv.setEditable(false);
        cmbPais.setEnabled(false); 
        cmbPais.setEditable(false);

        choice = 0;
    }//GEN-LAST:event_RBNacionalActionPerformed

    private void cmbPaisActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cmbPaisActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_cmbPaisActionPerformed

    private void cmbDepActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cmbDepActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_cmbDepActionPerformed

    private void EditarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_EditarActionPerformed
                                         
          if( txtRuc.getText( ).length()<11 ) 
{ JOptionPane.showMessageDialog(null,"Ruc debe contener 11 dígitos","Error",JOptionPane.ERROR_MESSAGE); 
}  else {
        if(choice==0){//Nacional
           String depa=(String)cmbDep.getSelectedItem();
            String ciu=(String)cmbDep.getSelectedItem();
          //  Nacional n = new Nacional((String)cmbDep.getSelectedItem(),(String)cmbCiu.getSelectedItem());
           Nacional n = new Nacional(depa,ciu);
            n.setId(Integer.parseInt(txtId.getText()));
            n.setRUC(txtRuc.getText());
            n.setRazonSocial(txtRazon.getText());
            n.setDireccion(txtDir.getText());
            n.setRepresentante(txtRep.getText());
            n.setLineaCred(Float.valueOf(txtLinea.getText()));
            n.setDepartamento(depa);
            n.setCiudad(ciu);  
            n.setTipo("N");  
        service.editaCliente(n);
         }
         else{//Internacional
            float divisa=Float.parseFloat(txtDiv.getText());
               String pais=(String)cmbPais.getSelectedItem();
         
            Internacional n = new Internacional(divisa,pais);
            n.setId(Integer.parseInt(txtId.getText()));
            n.setRUC(txtRuc.getText());
            n.setRazonSocial(txtRazon.getText());
            n.setDireccion(txtDir.getText());
            n.setRepresentante(txtRep.getText());
            n.setLineaCred(Float.valueOf(txtLinea.getText()));
            n.setDivisa(divisa);
            n.setPais(pais);
            n.setTipo("I");

  service.editaCliente(n);
         }
           Actualizar();
           }
    }//GEN-LAST:event_EditarActionPerformed

    private void TablaClienteMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_TablaClienteMouseClicked
   int rowSel = TablaCliente.getSelectedRow();
        String idCliente=TablaCliente.getValueAt(rowSel,0).toString();
        String ruc=TablaCliente.getValueAt(rowSel,1).toString();
        String razon=TablaCliente.getValueAt(rowSel,2).toString();
        String dir=TablaCliente.getValueAt(rowSel,3).toString();
        String Rep=TablaCliente.getValueAt(rowSel,4).toString();
        String Lin=TablaCliente.getValueAt(rowSel,5).toString();
        String Dep= TablaCliente.getValueAt(rowSel,6).toString();
        String Ciu=TablaCliente.getValueAt(rowSel,7).toString();
        String Div=TablaCliente.getValueAt(rowSel,8).toString();
        String Pais=TablaCliente.getValueAt(rowSel,9).toString();
       
        
        Cliente cli=service.queryByCliente(idCliente);
 
        txtId.setText(idCliente);
        txtRuc.setText(ruc);
        txtRazon.setText(razon);    
        txtDir.setText(dir);
        txtRep.setText(Rep);
        txtLinea.setText(Lin);
        cmbDep.setSelectedItem(Dep);
        cmbCiu.setSelectedItem(Ciu);
        txtDiv.setText(Div);
        cmbPais.setSelectedItem(Pais);
        choice = 1;
        if (txtDiv.getText().equals("")) choice = 0;
                
        
        //
    }//GEN-LAST:event_TablaClienteMouseClicked

    private void txtRucKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtRucKeyTyped
 char car = evt.getKeyChar();
      if(txtRuc.getText().length()>=11) evt.consume();
      if((car<'0' || car>'9')) evt.consume();        // TODO add your handling code here:
    }//GEN-LAST:event_txtRucKeyTyped

    private void txtRepKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtRepKeyTyped
           char car = evt.getKeyChar();    
if((car<'a' || car>'z') && (car<'A' || car>'Z') 
   && (car!=(char)KeyEvent.VK_SPACE))
{
   evt.consume();
}
if(txtRep.getText().length()>=50) evt.consume();
// TODO add your handling code here:
    }//GEN-LAST:event_txtRepKeyTyped

    private void txtLineaKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtLineaKeyTyped
        char a=evt.getKeyChar();
String texto;
//javax.swing.JTextField jTexto = new javax.swing.JTextField();
if ( "txtLinea".equals(evt.getComponent().getName()))
texto=txtLinea.getText().toString();
else
texto=txtLinea.getText().toString();
if ((!(a>=KeyEvent.VK_0 && a<=KeyEvent.VK_9)) && (!(a==KeyEvent.VK_PERIOD))) {
evt.consume();
}
if (a==KeyEvent.VK_PERIOD) {
if (texto.indexOf(".")>0) evt.consume();

}
 if (texto.length()>6) evt.consume();  
        // TODO add your handling code here:
    }//GEN-LAST:event_txtLineaKeyTyped

    private void txtDivKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtDivKeyTyped
char a=evt.getKeyChar();
String texto;
//javax.swing.JTextField jTexto = new javax.swing.JTextField();
if ( "txtDiv".equals(evt.getComponent().getName()))
texto=txtDiv.getText().toString();
else
texto=txtDiv.getText().toString();
if ((!(a>=KeyEvent.VK_0 && a<=KeyEvent.VK_9)) && (!(a==KeyEvent.VK_PERIOD))) {
evt.consume();
}
if (a==KeyEvent.VK_PERIOD) {
if (texto.indexOf(".")>0) evt.consume();

}
 if (texto.length()>6) evt.consume();  
        // TODO add your handling code here:
    }//GEN-LAST:event_txtDivKeyTyped

    private void txtRazonKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtRazonKeyTyped
 
        if(txtRazon.getText().length()>=50) evt.consume();// TODO add your handling code here:
    }//GEN-LAST:event_txtRazonKeyTyped

    private void txtDirKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtDirKeyTyped
if(txtDir.getText().length()>=50) evt.consume();
        // TODO add your handling code here:
    }//GEN-LAST:event_txtDirKeyTyped

    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
  txtId.setText("");
        txtRuc.setText("");
        txtRazon.setText("");
        txtDir.setText("");
        txtRep.setText("");
        txtLinea.setText("");
        txtDiv.setText("");
        // TODO add your handling code here:
    }//GEN-LAST:event_jButton2ActionPerformed
    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JRadioButton RBInter;
    private javax.swing.JRadioButton RBNacional;
    private javax.swing.JTable TablaCliente;
    private javax.swing.JComboBox cmbCiu;
    private javax.swing.JComboBox cmbDep;
    private javax.swing.JComboBox cmbPais;
    private javax.swing.JButton jButton2;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTextField txtDir;
    private javax.swing.JFormattedTextField txtDiv;
    private javax.swing.JTextField txtId;
    private javax.swing.JFormattedTextField txtLinea;
    private javax.swing.JTextField txtRazon;
    private javax.swing.JTextField txtRep;
    private javax.swing.JTextField txtRuc;
    // End of variables declaration//GEN-END:variables
}
